#ifndef __APP_BUFFER_H__
#define __APP_BUFFER_H__
#include "app_common.h"
#include "pthread.h"

// 读写缓冲结构体
typedef struct
{
    char *ptr;    // 缓冲区指针
    char len;     // 缓冲区长度
    int capacity; // 缓冲区容量
} sub_buffer_t;
// 大缓冲结构体
typedef struct
{
    sub_buffer_t *buffers[2];    // 读写缓冲区指针
    int read_index;              // 读数据缓冲区索引
    int write_index;             // 写数据缓冲区索引
    pthread_mutex_t write_mutex; // 写缓冲区锁
    pthread_mutex_t read_mutex;  // 读取缓冲区锁
} buffer_t;


buffer_t *App_Buffer_Init(int capacity);
GateState_t App_Buffer_Write(buffer_t *buffer, char *data, char len);
int App_Buffer_Read(buffer_t *buffer, char data[], int size);

void App_Buffer_Deinit(buffer_t *buffer);

#endif /* __APP_BUFFER_H__ */
